Requires Scripting PRO
The HealthStatisticsCollection class provides a structured representation of time-based grouped health statistics, such as daily, weekly, or monthly summaries. Each entry in the collection corresponds to one interval, and encapsulates its own HealthStatistics object.
This class is particularly useful for:
Each HealthStatisticsCollection is:
sources(): HealthSource[]Returns an array of HealthSource objects that contributed data to this collection.
Each HealthSource represents a device or app that generated health samples (e.g., Apple Watch, iPhone, a third-party app).
statistics(): HealthStatistics[]Returns all interval-based statistics in the collection as an array of HealthStatistics objects.
Each item represents one time interval, aligned by the query's anchorDate and intervalComponents.
statisticsFor(date: Date): HealthStatistics | nullReturns the HealthStatistics object that contains the given date, if it falls within any of the predefined intervals in the collection.
If no interval includes the given date, it returns null.
Use HealthStatisticsCollection when: